package 二分法查找;

public class BinarySearch {
    public void binarySearch(int num,int[] arr){
        int start_index = 0;
        int end_index = arr.length - 1;
        int middle_index = (start_index + end_index)/2;

        do {
            if (num == arr[middle_index]){
                System.out.println(middle_index);
                break;
            }
            if (num > arr[middle_index]){
                start_index = middle_index + 1;
            }
            if (num < arr[middle_index]) {
                end_index = middle_index - 1;
            }
            if (start_index >= end_index){
                System.out.println(num + "不在数组arr");
                break;
            }
            middle_index = (start_index + end_index)/2;
        }while (true);
    }
}
